﻿<%@ page pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
    <head>
    	<!-- Meta -->
        <meta charset="utf-8"/>
        <title>Génération de codes</title>
        
        <!-- CSS -->
		<link rel="stylesheet" href="medias/css/core.css" type="text/css" media="screen"/>
		
		<!-- JQuery -->
		<meta name="viewport" content="width=device-width, initial-scale=1"/> 
		<link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css"/>
		<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
		<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
    </head>
    
    <body>
    	<div data-role="page">
    	
			<div data-role="header">
				<div id="banniere">
					<br/> <br/>
					<h1 >CrecheBook</h1>
				</div>
				<div id="searchBox">
					<div class="ui-bar ui-bar-c">	
						<h2 id="nomCreche">
							<a href='search.jsp' rel='external' data-role='button' data-theme='c' data-corners='true' data-icon='home' data-inline='true'>Accueil</a>
							Administration
						</h2>
					</div>
			 	</div>
			</div>
	
			<div data-role="content">
				<div class="ui-grid-a">
					<div class="ui-block-a">
						<div id="menu">
							<a href="accueilAdmin.jsp"><p id="socialLink"><img src="medias/images/919406.jpg.png" width="50" height="50"/><span>Informations</span></p></a>
							<a href="inscriptions_adm.jsp"><p id="socialLink"><img src="medias/images/1367190697_sign-up_1_small.png" width="50" height="50"/><span>Inscriptions</span></p></a>
							<a href='code'><p id='socialLink'><img src='medias/images/key.png' width='50' height='50'/><span>Codes admin</span></p></a>
						</div>
					</div>
				
					<div class="ui-block-b">
						<div class="ui-bar ui-bar-b">
							<h2> Informations personnelles </h2>
						</div>
						<div id="informationGenerale">
					
							<%@page import = "Creche.Admin.Administrateur" %>
							<%
								// Redirection
								Administrateur admin = (Administrateur)request.getSession().getAttribute("session");
						
								if (admin != null) {
									if (admin.getStatut()) {
										String infoCreche = "<p class='col'>";
										infoCreche += "<strong> ID : </strong>" + admin.getIdentifiant() +"<br/>";
										infoCreche += "<strong> Email : </strong>" + admin.getEmail()+"<br/>";
										infoCreche += "<strong> Ville : </strong>" + admin.getVille() +"</p>";
										
										infoCreche += "<p style='margin:auto;width:250px;'><a href='deconnexion' data-ajax='false'><input type='button' data-theme='a' value='D&#233;connexion' class='button1'></a></p>";
										out.print(infoCreche);
									}
									else response.sendRedirect("connexion");
								}
								else response.sendRedirect("connexion"); 
							%>
						
						</div> 
					</div>
				</div> <br/>
			
				<div class="ui-bar ui-bar-c">
					<h2> Codes </h2>
				</div> <br/>
				
				<div class="ui-grid-a">
					<div class="ui-block-a">
						<div id="menu">
							<form method="post" action="code" data-ajax="false">
					            <fieldset>
					                <p class="intro">Générer code pour :</p>
					                <br/>
					 				
					 				<select name="statut" data-native-menu="false">
									  <option value="" data-placeholder="true"> Statut </option>
									  <option value="false"> Admin </option>
									  <option value="true"> SuperAdmin </option>
									</select>
									<p class="erreur">${form.erreurs['statut']}</p>
					                
					                <input type="submit" value="Générer" name="valStatut" data-theme="e"/>
					                <br/>
					                
					                
					                <%-- On stocke dans des variables de sessions le résultat à afficher et son style css --%>
					                <c:set var="resultat" value="${form.resultat}" scope="session"/>
					                <c:set var="css" value="${empty form.erreurs ? 'succes' : 'erreur'}" scope="session"/>
					                
					                <%@page import = "Servlet.User.CodeServlet" %>
					                <% String bouton = (String) request.getSession().getAttribute("bouton1");
					                   String result = (String) request.getSession().getAttribute("resultat");
					                   String css =    (String) request.getSession().getAttribute("css");
					                
					                	if (bouton != null) {
					           				out.print("<p class=\'"+ css +"\'>" + result + "</p> <br/>");
					           			}
					           		%>
					                
					                <p class="intro">Envoyer code par @email</p>
					                <input type="email" id="email" name="email" value="<c:out value="${admin.email}"/>" maxlength="60"/>
					                <p class="erreur">${form.erreurs['email']}</p>
					                
					                <input type="submit" value="Envoyer" name="valMail" data-theme="b"/>
					                <br/>
					                
					                <% bouton = (String) request.getSession().getAttribute("bouton2");
					                   result = (String) request.getSession().getAttribute("resultat");
					                   css =    (String) request.getSession().getAttribute("css");
					    			
					                	if (bouton != null) {
					           				out.print("<p class=\'"+ css +"\'>" + result + "</p> <br/>");
					           			}
					           		%>
					            </fieldset>
				        	</form>
				        </div>
					</div>
				
					<div class="ui-block-b">
						<div class="ui-bar ui-bar-b">
							<h2> Code à envoyer </h2>
						</div>
						<div id="informationGenerale">
							
							<%@page import = "CodeAdmin.Code" %>
							<%
								Code code = (Code)request.getSession().getAttribute("code");
								
								if (code != null) {
									String statut = "";
									
									if (code.getStatut()) statut = "SuperAdmin";
									else statut = "Admin";
									
									String infoCode = "<p class='col'>";
									infoCode += "<strong> Statut : </strong>" + statut + "<br/>";
									infoCode += "<strong> Code : </strong>" + code.getCode() + "</p>";
									out.print(infoCode);
								}
							%>
							
						</div> 
					</div>
				</div>
    		</div>
	
			<div data-role="footer">
				<h4 style="margin:30px;">
					<strong> CrecheBook 2013</strong> <br>
					<a href="legal.jsp" data-ajax="false">Mentions&nbsp;l&eacute;gales</a>&nbsp;|&nbsp;
					<a href="connexion" data-ajax="false">Administateur</a>
				</h4>
			</div>
			
		</div>
    </body>
</html>